// Copyright 2009 Google Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

#ifndef POPDIAG_UI_BROWSER_H__
#define POPDIAG_UI_BROWSER_H__

#include <QtCore/QUrl>
#include <QtGui/QTextBrowser>
#include <QtCore/QProcess>

namespace popdiag {

// a browser that renders like a label, and executes external
// links in the native browser.  Note that this is drawn in
// a frame.  That means that it will be indented a pixel or
// two from the surrounding material.  I haven't figured out
// how to fix this yet.
//
// Also as of the moment the browser objects are much taller
// than they need to be.
class Browser : public QTextBrowser {
  Q_OBJECT
 public:
  Browser(QWidget *parent, const QSize &size);
  virtual ~Browser();

  virtual QSize sizeHint();

  void LaunchUrlInNativeBrowser(const QUrl &url);

 private slots:
  void LaunchUrl(const QUrl &url);
  void CancelNavigation();
  void ResizeToFitText();

 private slots:
  void OnProcessError(QProcess::ProcessError error);
  void OnProcessExit(int code, QProcess::ExitStatus status);

 private:
  const QSize size_;
  QProcess *process_;
};

}  // namespace popdiag

#endif  // POPDIAG_UI_BROWSER_H__
